package com.zd.hamster.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.stream.Collectors;

/**
 * 文件删除
 * @author zhang
 *
 */
public class FileDeleter {

	/**
	 * 删除
	 * @param url
	 * @return
	 * @throws IOException
	 */
	public String del(String url) throws IOException {
		URL u = new URL(url);
		HttpURLConnection conn = null;
		try {
			conn = (HttpURLConnection) u.openConnection();
			conn.setDoInput(true);
			conn.setRequestMethod("DELETE");
			conn.connect();
			try(BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
				return reader.lines().collect(Collectors.joining());
			}
		} finally {
			conn.disconnect();
		}
	}
}
